package com.lixiaoyi.ems.controller;

import cn.dsna.util.images.ValidateCode;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @Author 李小毅
 * @Description
 * @Date 2022-05-18
 */

@WebServlet("/createCode")
public class CreateCodeController extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        ValidateCode validateCode = new ValidateCode(200,30,4,10);
        String codes = validateCode.getCode();

        //存储进session中
        HttpSession session = request.getSession();
        session.setAttribute("codes",codes);

        //展示在页面上
        validateCode.write(response.getOutputStream());
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
